﻿using CrateMayhem.Common.Model;

namespace CrateMayhem.WinRT.Controls
{
    public static class WorldExtensions
    {
        public delegate void AddHandler(GameGrid grid, int row, int col);

        public static void AddMatchingParts(
            this World world, 
            GameGrid grid, 
            int rowOffset, 
            int colOffset, 
            char search, 
            AddHandler addHandler)
        {
            var row = rowOffset;

            foreach (var line in world.Layout)
            {
                var col = colOffset;

                foreach (var l in line)
                {
                    if (l.Equals(search))
                    {
                        addHandler(grid, row, col);
                    }

                    col++;
                }

                row++;
            }
        }
    }
}